package cn.gson.zuche.controller.admin;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.gson.zuche.model.bean.UserType;
import cn.gson.zuche.model.dao.UserTypeDao;

/**
 * Servlet implementation class Guanliyuantype
 */
@WebServlet("/huiyuantype")
public class HuiYuantype extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private UserTypeDao dao=new UserTypeDao();
    private UserType t=new UserType();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	String hydj=null;
	hydj=request.getParameter("hydj");
	String sxjf=request.getParameter("sxjf");
	String sxzk=request.getParameter("sxzk");
	String id=null;
	id=request.getParameter("id");
	if(!"".equals(id)&&null!=id){		
		String[] a=new String[100];
		a=id.split(",");
		System.out.println(a);
		for (int i = 0; i < a.length; i++) {
			try {
				dao.delete(a[i]);
			} catch (SQLException e) {					
				e.printStackTrace();
			}
		}
	}	
	
	if(!"".equals(hydj)&&null!=hydj){
		t.setUsertypename(hydj);
		t.setUsertypeupjf(sxjf);
		t.setUsertypecut(Double.parseDouble(sxzk));
		try {
			dao.insert(t);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
		try {
		List<UserType> list=dao.findAll();
		request.setAttribute("usertype",list);
	} catch (SQLException e) {
		e.printStackTrace();
	}
		request.getRequestDispatcher("WEB-INF/jsp/adminjsp/huiyuantype.jsp").forward(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		doGet(request, response);
	}

}
